#ifndef __HEAD_H_
#define __HEAD_H_

#include <REGX51.H>

typedef unsigned char uint8_t;
typedef enum { LEFT, RIGHT } LCD_SIDE;

#define LCD_OFF 0x3E
#define LCD_ON 0x3F
#define PAGE_ADD 0xB8
#define COL_ADD 0x40
#define LINE_INIT 0xC0

#define PROGRAM_END while (1)

#define SWITCH_SCREEN(SIDE)    \
    do {                       \
        CS2 = !(CS1 = (SIDE)); \
    } while (0)

#define DELAY(t)                     \
    do {                             \
        uint8_t i, __t = (t);        \
        while (__t--)                \
            for (i = 0; i < 10; i++) \
                ;                    \
    } while (0)

#define DATA_BUS P1

#define WIDTH 128
#define HEIGHT 64
#define PAGE_SIZE 8

sbit CS1 = P2 ^ 4;
sbit CS2 = P2 ^ 3;
sbit RS = P2 ^ 2;
sbit RW = P2 ^ 1;
sbit E = P2 ^ 0;

void check_busy();

void lcd_write(uint8_t status, uint8_t datas);
void lcd_format(const char* fmt, ...);
void lcd_init();
void lcd_cls();
void lcd_display(LCD_SIDE side, uint8_t code* bmp);

#endif  // __HEAD_H_